function addTestCasePage() {
    var interfaceId = $("#interfaceId").val();
    window.location.href = "/testCase/addTestCasePage?interfaceId=" + interfaceId;
}

function run() {
    var testCases = $("#dataTable").bootstrapTable("getSelections");
    if (testCases.length <= 0) {
        Ewin.alert("必须选择一条数据操作");
        return
    }
    /**
     * 把所有选择的测试用例放入一个数组里面去
     * **/
    var caseIds = [];
    for (var i = 0; i < testCases.length; i++) {
        var testCaseId = testCases[i].id;
        caseIds.push(testCaseId);
    }
    runTest.runTestByCase(caseIds);
}

/**
 * 测试断言表达式
 * **/
function check() {
    var expressionData = $("#expressionTable").bootstrapTable("getData");
    var obj = resultEditor.get();
    var expectResult = JSON.stringify(obj);
    if (null == obj || expectResult == "{}") {
        Ewin.alert("当前的预期结果内容为空,无法测试表达式");
        return
    }
    if (expressionData == null || expressionData.length == 0) {
        Ewin.alert("当前的表达式内容为空,无法测试表达式");
        return
    }
    var expression = JSON.stringify(expressionData);
    expressionCheck(expression, expectResult)
}

function modifyTestCase() {
    var testCases = $("#dataTable").bootstrapTable("getSelections");
    if (testCases.length <= 0) {
        Ewin.alert("必须选择一条数据操作");
        return
    }
    if (testCases.length > 1) {
        Ewin.alert("只能选择一条数据操作");
        return
    }
    var id = testCases[0].id;
    var interfaceType = $("#interfaceType").val();
    window.location.href = "/testCase/modifyTestCasePage?id=" + id + "&interfaceType=" + interfaceType;
}

function deleteTestCase() {
    var testCases = $("#dataTable").bootstrapTable("getSelections");
    if (testCases.length <= 0) {
        Ewin.alert("必须选择一条数据操作");
        return
    }
    var caseId = [];
    for (var i = 0; i < testCases.length; i++) {
        caseId.push(testCases[i].id)
    }
    Ewin.confirm({message: "确认要删除测试用例吗?如果删除那么测试计划中的用例也会失效!"}).on(function (e) {
        if (!e) {
            return;
        }
        var url = "/testCase/deleteTestCase";
        $.ajax({
            url: url,
            method: "post",
            /**必须加上这个属性，才可以传入数据参数**/
            traditional: true,
            data: {
                caseIds: caseId
            }, success: function (result) {
                if (result.success) {
                    $("#dataTable").bootstrapTable("refresh")
                } else {
                    Ewin.alert(result.msg);
                }
            }
        })
    });

}